// 外交系统类型定义

import type { ResourceCost } from './resources'

export interface Faction {
  id: string
  name: string
  type: FactionType
  personality: FactionPersonality
  strength: FactionStrength
  territory: string[]
  relationships: Record<string, Relationship>
  traits: FactionTrait[]
  isPlayer: boolean
  isActive: boolean
}

export type FactionType = 'empire' | 'federation' | 'corporation' | 'collective' | 'nomads' | 'ai' | 'ancient'

export interface FactionPersonality {
  aggression: number // 0-100
  cooperation: number // 0-100
  expansion: number // 0-100
  technology: number // 0-100
  trade: number // 0-100
}

export interface FactionStrength {
  military: number
  economy: number
  technology: number
  influence: number
}

export interface FactionTrait {
  id: string
  name: string
  description: string
  effects: TraitEffect[]
}

export interface TraitEffect {
  type: 'diplomacy' | 'military' | 'economy' | 'research'
  modifier: number
  description: string
}

export interface Relationship {
  factionId: string
  status: DiplomaticStatus
  opinion: number // -100 to 100
  trust: number // 0-100
  fear: number // 0-100
  treaties: Treaty[]
  history: DiplomaticEvent[]
}

export type DiplomaticStatus = 'war' | 'hostile' | 'neutral' | 'friendly' | 'allied'

export interface Treaty {
  id: string
  type: TreatyType
  participants: string[]
  terms: TreatyTerm[]
  duration: number
  signedAt: number
  isActive: boolean
}

export type TreatyType = 'non_aggression' | 'trade' | 'research' | 'military' | 'alliance' | 'vassalage'

export interface TreatyTerm {
  type: 'resource_exchange' | 'military_support' | 'research_sharing' | 'territory_access' | 'tribute'
  details: Record<string, any>
  value?: number
}

export interface DiplomaticEvent {
  id: string
  type: EventType
  participants: string[]
  timestamp: number
  opinionChange: number
  description: string
}

export type EventType = 'first_contact' | 'trade_deal' | 'treaty_signed' | 'treaty_broken' | 'war_declared' | 'peace_made' | 'insult' | 'gift' | 'betrayal'

export interface DiplomaticAction {
  id: string
  name: string
  type: ActionType
  target: string
  costs?: ResourceCost[]
  requirements: ActionRequirement[]
  effects: ActionEffect[]
  cooldown?: number
}

export type ActionType = 'propose_treaty' | 'declare_war' | 'offer_peace' | 'send_gift' | 'demand_tribute' | 'insult' | 'praise' | 'spy' | 'sabotage'

export interface ActionRequirement {
  type: 'relationship' | 'resource' | 'technology' | 'military_strength'
  value: number
  operator: 'greater' | 'less' | 'equal'
}

export interface ActionEffect {
  type: 'opinion' | 'trust' | 'fear' | 'status'
  value: number
  duration?: number
}

export interface DiplomaticMission {
  id: string
  type: MissionType
  target: string
  duration: number
  progress: number
  success_chance: number
  rewards: MissionReward[]
  risks: MissionRisk[]
}

export type MissionType = 'establish_embassy' | 'trade_negotiation' | 'intelligence_gathering' | 'cultural_exchange' | 'military_cooperation'

export interface MissionReward {
  type: 'opinion' | 'resource' | 'technology' | 'information'
  value: number
  description: string
}

export interface MissionRisk {
  type: 'discovery' | 'failure' | 'incident'
  probability: number
  consequence: string
}

// 派系ID常量
export const FACTION_IDS = {
  TERRAN_FEDERATION: 'terran_federation',
  ZEPHYRIAN_EMPIRE: 'zephyrian_empire',
  CRYSTALLINE_COLLECTIVE: 'crystalline_collective',
  VOID_HUNTERS: 'void_hunters',
  ANCIENT_GUARDIANS: 'ancient_guardians',
  MERCHANT_GUILD: 'merchant_guild',
  NOMAD_CLANS: 'nomad_clans',
  AI_NETWORK: 'ai_network'
} as const